﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomerFloow.aspx.cs"
    Inherits="ZLDC.Estate.CM.CustomerFloow" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>客源跟进</title>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />

    <script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script src="../js/jquery/jquery.hiAlerts-min.js" type="text/javascript"></script>

    <script src="../js/LexunJS.js" type="text/javascript"></script>

    <link href="../css/PLG.css" rel="stylesheet" type="text/css" />

    <script src="../js/jShowDiv.js" type="text/javascript"></script>

    <link href="../js/jquery/style/jquery.hiAlerts.css" rel="stylesheet" type="text/css" />
    <base target="_self" />

    <script type="text/javascript">
        var currentPage = 1; // 当前页
        var pageSize = 6; // 每页显示多少条
        var pageall = 0; // 总页数
        var total = 0; // 总记录数
        $(document).ready(function() {
            var hid = LexunJS.GetQueryString("id"); //客源ID
            document.getElementById("customerId").value = hid;
            document.getElementById("followType").value = "电话沟通";

            //ShowFollow(1);
        });

        function submitOk() {
            //提交信息
            var fContent = document.getElementById("fcontent").value;
            if (fContent == "") {
                alert("请输入跟进内容！");
                return;
            }
            if (document.getElementById("cbSeeEstate").checked == true && document.getElementById("txtEstate").value == "") {
                alert("请选择所看房源！");
                return;
            }
            document.forms[0].submit();
        }
        function IsChecked() {
            var check = document.getElementById("cbSeeEstate");
            if (check.checked == true) {
                document.getElementById("IsSee").value = "1";
            } else {
                document.getElementById("IsSee").value = "0";
            }
        }

        function followTypeChange() {
            var followtype = document.getElementById("followType").value;
            var check = document.getElementById("cbSeeEstate");
            if (followtype == "带看房") {
                check.checked = true;
                document.getElementById("IsSee").value = "1";
            }
            else {
                check.checked = false;
            }
        }
        function ShowDialog(url) {
            var path = url;
            var parameter = "";
            var style = "dialogWidth:800px; dialogHeight:460px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
            var returnValue = window.showModalDialog(path, parameter, style);
            if (typeof (returnValue) == "undefined" || returnValue == null)
                return;
            var str = new Array();
            str = returnValue.split('|');
            document.getElementById("housingid").value = str[0];
            document.getElementById("txtEstate").value = str[1];
        }
        //默认查询跟进
        function ShowFollow(currentPage) {
            $("#divfollow").show();
            var id = LexunJS.GetQueryString("id");
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerCustomer.ashx',
                data: 'act=SelectCustomerFollow&id=' + id + '&page=' + currentPage + '&pagesize=' + pageSize,
                timeout: '10000',
                error: function() {
                    alert("修改失败！");
                },
                success: function(json) {
                    ShowFlowCallBack(json);
                }
            });
        }


        function HideFollow() {
            $("#divfollow").hide();
        }

        //点击刷新,查询跟进
        function ShowFollow1(currentPage) {
            var id = LexunJS.GetQueryString("id");
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerCustomer.ashx',
                data: 'act=SelectCustomerFollow&id=' + id + '&page=' + currentPage + '&pagesize=' + pageSize + '&refresh=1',
                timeout: '10000',
                error: function() {
                    alert("修改失败！");
                },
                success: function(json) {
                    ShowFlowCallBack(json);
                }
            });
        }
        //查询更多跟进
        function ShowFollow2(currentPage) {
            var id = LexunJS.GetQueryString("id");
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerCustomer.ashx',
                data: 'act=SelectCustomerFollow&id=' + id + '&page=' + currentPage + '&pagesize=1000&refresh=1',
                timeout: '10000',
                error: function() {
                    alert("修改失败！");
                },
                success: function(json) {
                    ShowFlowCallBack(json);
                }
            });
        }

        function ShowFlowCallBack(response) {
            var json = eval("(" + response + ")");
            var record = json.record;

            var page = json.page;

            currentPage = page.currentpage;
            pageall = parseInt(page.pageall);
            total = page.total;

            $("#divPage").html(""); // 清空

            $("#divPage").html("<a href=\"javascript:ShowFollow1(1)\">刷新</a>  <a href=\"javascript:ShowFollow2(1)\">更多...</a>");

            if (record == null || record.length == 0) return;
            $("#divfollow").html(""); // 显示列表
            var arr = [];
            arr.push("<table id='table1' style=\"word-break: break-all;\" width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
            arr.push("<tr>");
            arr.push("<td bgcolor='d3eaef' class='STYLE10'>");
            arr.push("序号");
            arr.push("</td>");
            arr.push("<td width='110' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("跟进时间</td>");
            arr.push("<td width='80' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("部门</td>");
            arr.push("<td width='50' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("跟进人</td>");
            arr.push("<td width='50' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("跟进方式</td>");
            arr.push("<td bgcolor='d3eaef' class='STYLE10'>");
            arr.push("跟进内容</td>");
            arr.push("<td bgcolor='d3eaef' class='STYLE10'>");
            arr.push("所看房源编号</td>");

            arr.push("</tr>");
            for (var i = 0; i < record.length; i++) {
                if (i % 2 == 0)
                    arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF' style='cursor: pointer;' >");
                else
                    arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED' style='cursor: pointer;' >");

                arr.push("<td class='STYLE6'>");
                arr.push(record[i].id);
                arr.push("</td>");
                arr.push("<td class='STYLE6'>");
                arr.push(record[i].fdate);
                arr.push("</td>");
                arr.push("<td class='STYLE6'>");
                arr.push(record[i].fdept);
                arr.push("</td>");
                arr.push("<td class='STYLE6'>");
                arr.push(record[i].fuser);
                arr.push("</td>");
                arr.push("<td class='STYLE6'>");
                arr.push(record[i].ftype);
                arr.push("</td>");
                arr.push("<td align='left' class='STYLE7'>");
                arr.push(record[i].fcontent);
                arr.push("</td>");
                arr.push("<td class='STYLE6'>");
                if (record[i].fhousingid == 0) {
                    arr.push("<font color='blue'>无看房记录</font></td>")
                } else {
                    arr.push("<a href='javascript:ShowDialogs(\"HousingDetail.aspx\",\"" + record[i].fhousingid + "\");'><font color='red'>" + record[i].fhousingid + "</font></a></td>");
                }

                arr.push("</tr>");
            }
            arr.push("</table>");
            $("#divfollow").html(arr.join('')); // 显示列表
        }

        function followTypeChange() {
            var followtype = document.getElementById("followType").value;
            var check = document.getElementById("cbSeeEstate");
            if (followtype == "带看房") {
                check.checked = true;
                document.getElementById("IsSee").value = "1";
            }
            else {
                check.checked = false;
            }
        }
        function IsChecked() {
            var check = document.getElementById("cbSeeEstate");
            if (check.checked == true) {
                document.getElementById("IsSee").value = "1";
                document.getElementById("followType").value = '带看房';
            } else {
                document.getElementById("IsSee").value = "0";
                document.getElementById("followType").value = '电话沟通';
            }
        }
        /*-----------------------------添加更进信息-------------------*/
        function submitOk() {
            //提交信息
            var fContent = document.getElementById("fcontent").value;
            if (fContent == "") {
                alert("请输入跟进内容！");
                return;
            }
            if (document.getElementById("cbSeeEstate").checked == true && document.getElementById("txtEstate").value == "") {
                alert("请选择所看房源！");
                return;
            }
            var cid = document.getElementById("customerId").value;
            var fType = document.getElementById("followType").value;
            var fcontent = document.getElementById("fcontent").value;
            var estate = document.getElementById("txtEstate").value;
            var IsSee = document.getElementById("IsSee").value;
            var hid = document.getElementById("housingid").value;

            var fdeptId = document.getElementById("ddeptid").value;
            var fdept = document.getElementById("ddept").value;
            var fUserId = document.getElementById("duserid").value;
            var fUser = document.getElementById("duser").value;

            $("#btnSave").attr("disabled", "true");
            $("#btnSave").attr("value", "正在提交...");

            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerCustomer.ashx',
                data: 'act=CustomerFollowSave1&customerId=' + cid + '&followType=' + fType + '&fcontent=' + fcontent + '&txtEstate=' + estate + '&IsSee=' + IsSee + '&housingid=' + hid + '&fdeptId=' + fdeptId + '&fdept=' + fdept + '&fUserId=' + fUserId + '&fUser=' + fUser,
                timeout: '20000',
                error: function() {
                    alert("提交失败！");
                    $("#btnSave").removeAttr("disabled");
                    $("#btnSave").attr("value", "提交");
                },
                success: function(json) {
                    $("#btnSave").removeAttr("disabled");
                    $("#btnSave").attr("value", "提交");

                    document.getElementById("fcontent").value = "";
                    document.getElementById("housingid").value = "0";
                    document.getElementById("txtEstate").value = "";
                    document.getElementById("IsSee").value = "0";
                    document.getElementById("cbSeeEstate").checked = false;
                    document.getElementById("followType").value = '电话沟通';


                    //ShowFollow(1);
                }
            });
        }
        //打开房源详情
        function ShowDialogs(url, id) {
            var url = "../PM/" + url + "?id=" + id;

            var style = "left = 50, screenX = 0, top = 50, screenY = 0, resizable = yes, scrollbars = yes,width=750px, height=450px,Toolbar=no,Location=no,Direction=no,Resizeable=no";
            window.open(url, '', style);

        }
    </script>

</head>
<body>
    <form id="form1" runat="server" >
   
   <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
            <tr>
                <td bgcolor="#FFFFFF" style="width: 8%; height: 25px;">
                    等级：
                </td>
                <td bgcolor="#FFFFFF" style="width: 20%; height: 25px;">
                    <select id="customerClass" name="customerClass" runat="server">
                    </select>
                </td>
                <td bgcolor="#FFFFFF" style="width: 12%; height: 25px;">
                    跟进方式：
                </td>
                <td bgcolor="#FFFFFF" style="width: 20%; height: 25px;">
                    <select id="followType" runat="server" name="followType" style="width: 50%" onchange="followTypeChange()">
                    </select>
                </td>
                
            </tr>
            <tr>
                <td bgcolor="#FFFFFF" style="width: 16%; height: 25px;">
                    <input id="cbSeeEstate" type="checkbox" onclick="IsChecked()" />是否看房 所看房源：
                </td>
                <td bgcolor="#FFFFFF" style="width: 20%; height: 25px;" colspan="3">
                    <table style="width: 98%; height: 25px;">
                        <tr>
                            <td style="width: 60%; height: 25px;" align="right">
                                <input id="txtEstate" style="width: 98%" name="txtEstate" type="text" readonly />
                            </td>
                            <td align="left" style="width: 30%">
                                <a href="javascript:ShowDialog('HousingList.aspx')">请选择</a>
                            </td>
                        </tr>
                    </table>
                </td>
                
            </tr>
            <tr>
                <td bgcolor="#FFFFFF" style="width: 12%; height: 25px;">
                    跟进内容：
                </td>
                <td bgcolor="#FFFFFF" style="width: 32%; height: 25px;" colspan="3">
                    <textarea id="fcontent" name="fcontent" style="width: 98%; height: 26px;"></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="4" align="center" bgcolor="#F7F7F7" style="width: 70%">
                    <input id="Button1" class="button_bak" type="button" value="提交" onclick="return submitOk()" />
                </td>
            </tr>
        </table>
        <div id="showButton"><a href="javascript:ShowFollow(1)">显示历史跟进</a>  <a href="javascript:HideFollow()">隐藏历史跟进</a></div>
    <div id="divfollow" onselectstart="return false">
    </div>
    <div id="divPage">
    </div>
    
    <input id="customerId" name="customerId" type="hidden" />
    <input id="housingid" name="housingid" type="hidden" />
    <input id="IsSee" name="IsSee" type="hidden" />
    <input id="ddept" name="ddept" runat="server" type="hidden" />
    <input id="ddeptid" name="ddeptid" runat="server" type="hidden" />
    <input id="duser" name="duser" runat="server" type="hidden" />
    <input id="duserid" name="duserid" runat="server" type="hidden" />
    </form>
</body>
</html>
